#!/usr/bin/env python
# coding=utf-8
"""
@Author  : youjia - 卞志伟
@file    : day_report_business.py
@contact : bianzhiwei@iyoujia.com
@time    : 2019-08-12 15:18 
@Desc    : 
@Software: PyCharm
"""
import os
import sys

# 当前文件的路径
pwd, filename = os.path.split(os.path.abspath(__file__))
# 当前文件的父路径
father_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
# 当前文件的前两级目录
grader_father = os.path.abspath(os.path.dirname(pwd) + os.path.sep + "..")
sys.path.append(pwd)
sys.path.append(father_path)
sys.path.append(grader_father)

from report_system.utils import excel_util
from report_system.utils import mail_util
from report_system.utils import mailbox_util
from report_system.utils.num_util import divi
from report_system.utils.enum_util import DAY_REPORT_BUSINESS_COLOR
from report_system.utils.channel_util import TUJIA, ZHENGUO, AIRBNB
from report_system.report_specify.business_specify import *
from report_system.report_specify.service_specify import *
from report_system.report_specify.comment_specify import comment_overview_city_month
from report_system.utils.development_util import debug

if debug:
    receivers = 'bianzhiwei@iyoujia.com'
    city_mails = mailbox_util.mails_test
else:
    receivers = 'yitangf@sweetome.com;yangweiwei@iyoujia.com;songweiyun@iyoujia.com;wujiming@iyoujia.com;' \
                'dt@iyoujia.com;wudi@city-home.cn;miaohaixia@city-home.cn;zhengliangl@sweetome.com;' \
                'wangsuxiao@city-home.cn;zhuqiang@iyoujia.com;xuzhehang@iyoujia.com;' \
                'qikai@iyoujia.com;yuyue@city-home.cn;huqi2@city-home.cn;' \
                'wangsuxiao@city-home.cn;zhangxian@city-home.cn'
    city_mails = None


def business_city(st=None, et=None):
    today = date_util.date_add(et, days=1) if et else date_util.curdate(0)
    yesterday = date_util.curdate()
    st = st if st else date_util.cur_month_first(days=1, dt=yesterday)
    et = et if et else yesterday
    city_today_df = city_sale_data(today, today)

    # im_city_today_df = im_city_day(st=today, et=today)
    # if im_city_today_df.__len__() == 0:
    #     today_df = city_today_df
    # else:
    #     today_df = pd.merge(city_today_df, im_city_today_df, how='outer')

    today_df = df_util.df_set_index(city_today_df, ["公司", "城市"])

    today_df = df_util.df_set_first_title(today_df, "今日数据")
    log.info("今日数据准备完毕。。。。。。。")

    city_yesterday_df = city_sale_data(et, et)
    city_last_year_df = city_sale_data_last_year(et, et)
    city_yesterday_df = pd.merge(city_yesterday_df, city_last_year_df, how='outer')
    # city_yesterday_df['日价同比增长'] = ""
    # city_yesterday_df['入住率同比增长'] = ""
    # city_yesterday_df[['日价同比增长', '入住率同比增长']] = city_yesterday_df.apply(lambda row: chain_ratio(row), axis=1)

    im_city_yesterday_df = im_city_day(st=et, et=et)
    yesterday_df = pd.merge(city_yesterday_df, im_city_yesterday_df, how='outer')
    yesterday_df = df_util.df_set_index(yesterday_df, ["公司", "城市"])

    yesterday_df['套均净利'] = yesterday_df.apply(lambda row: round(row['总净利'] / row['房量'], 2), axis=1)

    yesterday_df = yesterday_df[["日期", "房量", "可租率", "可售房源入住率", "在线房源入住率", "去年同期在线房源入住率", "预定订单中当日入住订单",
                                 "预定订单", "预定订单间夜", "GMV", "日价", "去年同期日价", "总净利", "套均净利", "REVPAR", "去年同期REVPAR",
                                 "im咨询回复率", "im咨询五分钟回复率", "im咨询完整回复率"]]

    yesterday_df = df_util.df_set_first_title(yesterday_df, "昨日数据")
    log.info("昨日数据准备完毕。。。。。。。")
    result_df = pd.merge(yesterday_df, today_df, how='outer', left_index=True, right_index=True)
    log.info("合并昨日数据、今日数据完毕。。。。。。。")

    month_order_df = month_order_city(st=st, et=et)
    month_order_df = df_util.df_set_index(month_order_df, ["公司", "城市"])
    log.info("月累计评论准备完毕。。。。。。。")
    city_month_df = city_sale_data(st, et)
    city_month_year_df = city_sale_data_last_year(st, et)
    city_month_df = pd.merge(city_month_df, city_month_year_df, how='outer')
    # city_month_df['日价同比增长'] = ""
    # city_month_df['入住率同比增长'] = ""
    # city_month_df[['日价同比增长', '入住率同比增长']] = city_month_df.apply(lambda row: chain_ratio(row), axis=1)

    # city_month_df['套均GMV'] = city_month_df['GMV'] / city_month_df['房量']
    # city_month_df['套均净利'] = city_month_df['总净利'] / city_month_df['房量']
    city_month_df['套均GMV'] = city_month_df.apply(lambda row: divi(row, 'GMV', '房量'), axis=1)
    city_month_df['套均净利'] = city_month_df.apply(lambda row: divi(row, '总净利', '房量'), axis=1)

    city_month_df = city_month_df[["公司", '城市', '可租率', '可售房源入住率', '在线房源入住率', '去年同期在线房源入住率', '预定订单', '预定订单间夜',
                                   '日价', '去年同期日价', 'REVPAR', '去年同期REVPAR', 'GMV', '总净利', '套均GMV', '套均净利']]

    log.info("月累计销售数据准备完毕。。。。。。。")
    im_city_month_df = im_city_day(st=st, et=et)
    log.info("月累计im数据准备完毕。。。。。。。")
    month_df = pd.merge(city_month_df, im_city_month_df, how='outer')
    log.info("合并月累计im数据、月累计销售数据完毕。。。。。。。")
    month_df = df_util.df_set_index(month_df, ["公司", "城市"])
    month_df = pd.merge(month_df, month_order_df, how='outer', left_index=True, right_index=True)
    log.info("合并月累计im数据、月累计销售数据、月累计评论完毕。。。。。。。")

    refund_df = city_refund_rate_month(st=st, et=et)
    refund_df = refund_df.reset_index()
    refund_df = df_util.df_set_index(refund_df, ["公司", "城市"])
    refund_df = refund_df[['退款率']]

    month_df = pd.merge(month_df, refund_df, how='outer', left_index=True, right_index=True)
    # 评论概况
    comment_overview_city_month_df = comment_overview_city_month(st=st, et=et)
    comment_overview_city_month_df = comment_overview_city_month_df[["公司", "城市", "评论率", "好评率", "差评率",
                                                                     "途家评论占比", "爱彼迎评论占比", "榛果评论占比"]]
    comment_overview_city_month_df = df_util.df_set_index(comment_overview_city_month_df, ["公司", "城市"])

    month_df = pd.merge(month_df, comment_overview_city_month_df, how='outer', left_index=True, right_index=True)
    log.info("合并月累计im数据、月累计销售数据、月累计评论完毕。。。。。。。")

    month_df = df_util.df_set_first_title(month_df, "累计数据")
    result_df = pd.merge(result_df, month_df, how='outer', left_index=True, right_index=True)

    result_df = result_df.reset_index()
    result_df = df_util.df_sort(result_df, [("昨日数据", "房量")])

    return {'经营日报-城市': result_df}, {'经营日报-城市': DAY_REPORT_BUSINESS_COLOR}


def business_online(st=None, et=None):
    today = date_util.date_add(et, days=1) if et else date_util.curdate(0)
    yesterday = date_util.curdate()
    st = st if st else date_util.cur_month_first(days=1, dt=yesterday)
    et = et if et else yesterday
    online_today_df = online_sale_data(today, today)
    # im_online_today_df = im_online_day(st=today, et=today)
    # if im_online_today_df.__len__() == 0:
    #     today_df = online_today_df
    # else:
    #     today_df = pd.merge(online_today_df, im_online_today_df, how='outer')
    today_df = df_util.df_set_index(online_today_df, ["公司", "城市", "门店", "门店销售"])
    today_df = df_util.df_set_first_title(today_df, "今日数据")
    log.info("今日数据准备完毕。。。。。。。")

    online_yesterday_df = online_sale_data(et, et)
    im_online_yesterday_df = im_online_day(st=et, et=et)

    yesterday_df = pd.merge(online_yesterday_df, im_online_yesterday_df, how='outer')
    yesterday_df = df_util.df_set_index(yesterday_df, ["公司", "城市", "门店", "门店销售"])
    yesterday_df = df_util.df_set_first_title(yesterday_df, "昨日数据")

    print('******' * 10)
    excel_util.pd_to_excel({"yesterday_df": yesterday_df}, "yesterday_df", merge_cells=True)

    log.info("昨日数据准备完毕。。。。。。。")
    result_df = pd.merge(yesterday_df, today_df, how='outer', left_index=True, right_index=True)
    log.info("合并昨日数据、今日数据完毕。。。。。。。")

    month_order_df = month_order_online(st=st, et=et)
    month_order_df = df_util.df_set_index(month_order_df, ["公司", "城市", "门店销售"])
    log.info("月累计评论准备完毕。。。。。。。")
    online_month_df = online_sale_data(st, et)
    # online_month_df['套均GMV'] = online_month_df['GMV'] / online_month_df['房量']
    # online_month_df['套均净利'] = online_month_df['总净利'] / online_month_df['房量']

    online_month_df['套均GMV'] = online_month_df.apply(lambda row: divi(row, 'GMV', '房量'), axis=1)
    online_month_df['套均净利'] = online_month_df.apply(lambda row: divi(row, '总净利', '房量'), axis=1)
    city_month_df = online_month_df[["公司", '城市', '门店销售', '可租率', '可售房源入住率', '预定订单', '预定订单间夜', '日价',
                                     'REVPAR', 'GMV', '总净利', '套均GMV', '套均净利']]

    log.info("月累计销售数据准备完毕。。。。。。。")
    im_online_month_df = im_online_day(st=st, et=et)
    log.info("月累计im数据准备完毕。。。。。。。")
    month_df = pd.merge(city_month_df, im_online_month_df, how='outer')
    log.info("合并月累计im数据、月累计销售数据完毕。。。。。。。")
    month_df = df_util.df_set_index(month_df, ["公司", "城市", "门店销售"])
    month_df = pd.merge(month_df, month_order_df, how='outer', left_index=True, right_index=True)
    log.info("合并月累计im数据、月累计销售数据、月累计评论完毕。。。。。。。")

    refund_df = online_refund_rate_month(st=st, et=et)
    refund_df = refund_df.reset_index()
    refund_df = refund_df.rename(columns={'销售': '门店销售'})
    refund_df = df_util.df_set_index(refund_df, ["公司", "城市", "门店销售"])
    refund_df = refund_df[['退款率']]
    month_df = pd.merge(month_df, refund_df, how='outer', left_index=True, right_index=True)

    month_df = df_util.df_set_first_title(month_df, "累计数据")
    result_df = pd.merge(result_df, month_df, how='outer', left_index=True, right_index=True)
    result_df = result_df.reset_index()
    return {'经营日报-销售': result_df}, {'经营日报-销售': DAY_REPORT_BUSINESS_COLOR}


def business_service(st=None, et=None):
    today = date_util.date_add(et, days=1) if et else date_util.curdate(0)
    yesterday = date_util.curdate()
    st = st if st else date_util.cur_month_first(days=1, dt=yesterday)
    et = et if et else yesterday
    service_today_df = service_sale_data(today, today)
    # im_service_today_df = im_service_day(st=today, et=today)
    # if im_service_today_df.__len__() == 0:
    #     today_df = im_service_today_df
    # else:
    #     today_df = pd.merge(service_today_df, im_service_today_df, how='outer')
    today_df = df_util.df_set_index(service_today_df, ["公司", "城市", "服务中心"])

    today_df = df_util.df_set_first_title(today_df, "今日数据")
    log.info("今日数据准备完毕。。。。。。。")

    service_yesterday_df = service_sale_data(et, et)

    service_last_year_df = service_sale_data_last_year(et, et)
    service_yesterday_df = pd.merge(service_yesterday_df, service_last_year_df, how='outer')
    # service_yesterday_df['日价同比增长'] = ""
    # service_yesterday_df['入住率同比增长'] = ""
    # service_yesterday_df[['日价同比增长', '入住率同比增长']] = service_yesterday_df.apply(lambda row: chain_ratio(row), axis=1)

    im_service_yesterday_df = im_service_day(st=et, et=et)
    yesterday_df = pd.merge(service_yesterday_df, im_service_yesterday_df, how='outer')
    yesterday_df = df_util.df_set_index(yesterday_df, ["公司", "城市", "服务中心"])

    yesterday_df = yesterday_df[["日期", "房量", "可租率", "可售房源入住率", "在线房源入住率", "去年同期在线房源入住率", "预定订单中当日入住订单",
                                 "预定订单", "预定订单间夜", "GMV", "日价", "去年同期日价", "总净利", "REVPAR", "去年同期REVPAR",
                                 "im咨询回复率", "im咨询五分钟回复率", "im咨询完整回复率"]]

    yesterday_df = df_util.df_set_first_title(yesterday_df, "昨日数据")
    log.info("昨日数据准备完毕。。。。。。。")

    result_df = pd.merge(yesterday_df, today_df, how='outer', left_index=True, right_index=True)
    log.info("合并昨日数据、今日数据完毕。。。。。。。")

    month_order_df = month_order_service(st=st, et=et)
    month_order_df = df_util.df_set_index(month_order_df, ["公司", "城市", "服务中心"])
    log.info("月累计评论准备完毕。。。。。。。")
    service_month_df = service_sale_data(st, et)
    service_month_year_df = service_sale_data_last_year(st, et)
    service_month_df = pd.merge(service_month_df, service_month_year_df, how='outer')
    # service_month_df['日价同比增长'] = ""
    # service_month_df['入住率同比增长'] = ""
    # service_month_df[['日价同比增长', '入住率同比增长']] = service_month_df.apply(lambda row: chain_ratio(row), axis=1)

    # service_month_df['套均GMV'] = service_month_df['GMV'] / service_month_df['房量']
    # service_month_df['套均净利'] = service_month_df['总净利'] / service_month_df['房量']
    service_month_df['套均GMV'] = service_month_df.apply(lambda row: divi(row, 'GMV', '房量'), axis=1)
    service_month_df['套均净利'] = service_month_df.apply(lambda row: divi(row, '总净利', '房量'), axis=1)
    service_month_df = service_month_df[["公司", '城市', '服务中心', '可租率', '可售房源入住率', '在线房源入住率', '去年同期在线房源入住率', '预定订单',
                                         '预定订单间夜', '日价', '去年同期日价', 'REVPAR', '去年同期REVPAR', 'GMV', '总净利',
                                         '套均GMV', '套均净利']]

    log.info("月累计销售数据准备完毕。。。。。。。")
    im_service_month_df = im_service_day(st=st, et=et)
    log.info("月累计im数据准备完毕。。。。。。。")
    month_df = pd.merge(service_month_df, im_service_month_df, how='outer')
    log.info("合并月累计im数据、月累计销售数据完毕。。。。。。。")
    month_df = df_util.df_set_index(month_df, ["公司", "城市", "服务中心"])

    month_df = pd.merge(month_df, month_order_df, how='outer', left_index=True, right_index=True)
    log.info("合并月累计im数据、月累计销售数据、月累计评论完毕。。。。。。。")

    refund_df = service_refund_rate_month(st=st, et=et)
    refund_df = refund_df.reset_index()
    refund_df = df_util.df_set_index(refund_df, ["公司", "城市", "服务中心"])
    refund_df = refund_df[['退款率']]
    month_df = pd.merge(month_df, refund_df, how='outer', left_index=True, right_index=True)

    month_df = df_util.df_set_first_title(month_df, "累计数据")
    result_df = pd.merge(result_df, month_df, how='outer', left_index=True, right_index=True)
    # result_df = pd.merge(result_df, airbnb_df, how='left', left_index=True, right_index=True)
    result_df = result_df.reset_index()
    # result_df = df_util.df_set_index(result_df, '城市')

    return {'经营日报-服务中心': result_df}, {'经营日报-服务中心': DAY_REPORT_BUSINESS_COLOR}


def business_work(st=None, et=None):
    today = date_util.date_add(et, days=1) if et else date_util.curdate(0)
    yesterday = date_util.curdate()
    st = st if st else date_util.cur_month_first(days=1, dt=yesterday)
    et = et if et else yesterday
    work_today_df = work_sale_data(today, today)
    # im_work_day_df = im_work_day(st=today, et=today, has_first=False)
    #
    # if im_work_day_df.__len__() == 0:
    #     today_df = im_work_day_df
    # else:
    #     today_df = pd.merge(work_today_df, im_work_day_df, how='outer')
    today_df = df_util.df_set_index(work_today_df, ["公司", "城市", "门店"])

    today_df = df_util.df_set_first_title(today_df, "今日数据")
    log.info("今日数据准备完毕。。。。。。。")

    work_yesterday_df = work_sale_data(et, et)

    work_last_year_df = work_sale_data_last_year(et, et)
    work_yesterday_df = pd.merge(work_yesterday_df, work_last_year_df, how='outer')
    # work_yesterday_df['日价同比增长'] = ""
    # work_yesterday_df['入住率同比增长'] = ""
    # work_yesterday_df[['日价同比增长', '入住率同比增长']] = work_yesterday_df.apply(lambda row: chain_ratio(row), axis=1)

    im_work_yesterday_df = im_work_day(st=et, et=et, has_first=False)
    yesterday_df = pd.merge(work_yesterday_df, im_work_yesterday_df, how='outer')
    yesterday_df = df_util.df_set_index(yesterday_df, ["公司", "城市", "门店"])

    yesterday_df = yesterday_df[["日期", "房量", "可租率", "可售房源入住率", "在线房源入住率", "去年同期在线房源入住率", "预定订单中当日入住订单",
                                 "预定订单", "预定订单间夜", "GMV", "日价", "去年同期日价", "总净利", "REVPAR", "去年同期REVPAR",
                                 "咨询数", "回复数", "五分钟回复数", "完整回复数", "im咨询回复率", "im咨询五分钟回复率", "im咨询完整回复率"]]

    yesterday_df = df_util.df_set_first_title(yesterday_df, "昨日数据")
    log.info("昨日数据准备完毕。。。。。。。")
    result_df = pd.merge(yesterday_df, today_df, how='outer', left_index=True, right_index=True)
    log.info("合并昨日数据、今日数据完毕。。。。。。。")

    month_order_df = month_order_work(st=st, et=et)
    month_order_df = df_util.df_set_index(month_order_df, ["公司", "城市", "门店"])
    log.info("月累计评论准备完毕。。。。。。。")
    work_month_df = work_sale_data(st, et)
    work_month_year_df = work_sale_data_last_year(st, et)
    work_month_df = pd.merge(work_month_df, work_month_year_df, how='outer')
    # work_month_df['日价同比增长'] = ""
    # work_month_df['入住率同比增长'] = ""
    # work_month_df[['日价同比增长', '入住率同比增长']] = work_month_df.apply(lambda row: chain_ratio(row), axis=1)

    # service_month_df['套均GMV'] = service_month_df['GMV'] / service_month_df['房量']
    # service_month_df['套均净利'] = service_month_df['总净利'] / service_month_df['房量']
    work_month_df['套均GMV'] = work_month_df.apply(lambda row: divi(row, 'GMV', '房量'), axis=1)
    work_month_df['套均净利'] = work_month_df.apply(lambda row: divi(row, '总净利', '房量'), axis=1)
    work_month_df = work_month_df[["公司", '城市', "门店", '可租率', '可售房源入住率', '在线房源入住率', '去年同期在线房源入住率', '预定订单',
                                   '预定订单间夜', '日价', '去年同期日价', 'REVPAR', '去年同期REVPAR', 'GMV', '总净利',
                                   '套均GMV', '套均净利']]

    log.info("月累计销售数据准备完毕。。。。。。。")
    im_work_month_df = im_work_day(st=st, et=et, has_first=False)
    log.info("月累计im数据准备完毕。。。。。。。")
    month_df = pd.merge(work_month_df, im_work_month_df, how='outer')
    log.info("合并月累计im数据、月累计销售数据完毕。。。。。。。")
    month_df = df_util.df_set_index(month_df, ["公司", "城市", "门店"])

    month_df = pd.merge(month_df, month_order_df, how='outer', left_index=True, right_index=True)
    log.info("合并月累计im数据、月累计销售数据、月累计评论完毕。。。。。。。")

    refund_df = work_refund_rate_month(st=st, et=et)
    refund_df = refund_df.reset_index()
    refund_df = df_util.df_set_index(refund_df, ["公司", "城市", "门店"])
    refund_df = refund_df[['退款率']]

    month_df = pd.merge(month_df, refund_df, how='outer', left_index=True, right_index=True)

    month_df = df_util.df_set_first_title(month_df, "累计数据")
    result_df = pd.merge(result_df, month_df, how='outer', left_index=True, right_index=True)
    # result_df = pd.merge(result_df, airbnb_df, how='left', left_index=True, right_index=True)
    result_df = result_df.reset_index()
    # result_df = df_util.df_set_index(result_df, '城市')
    result_df = df_util.df_sort(result_df, [("昨日数据", "房量")])
    return {'经营日报-门店': result_df}, {'经营日报-门店': DAY_REPORT_BUSINESS_COLOR}


def business_house(st=None, et=None):
    test_dict = {}

    yesterday = date_util.curdate()
    st = st if st else date_util.cur_month_first(days=1, dt=yesterday)
    et = et if et else yesterday

    house_base_df = house_base_data()
    house_base_df = df_util.df_set_index(house_base_df, ["房屋ID", "城市"])
    house_base_df = df_util.df_set_first_title(house_base_df, "基础数据")
    log.info("房屋基础数据准备完毕！")
    test_dict['基础数据'] = house_base_df

    house_rent_day_df = house_rent_day(dt=et)
    house_rent_day_df = df_util.df_set_index(house_rent_day_df, "房屋ID")
    log.info("未来可租、已售间夜准备完毕！")
    test_dict['未来可租'] = house_rent_day_df
    house_price_df = house_price(dt=et)
    house_price_df = df_util.df_set_index(house_price_df, "房屋ID")
    log.info("未来各渠道价格准备完毕！")
    test_dict['未来各渠道价格准备完毕'] = house_price_df

    day_df = pd.merge(house_price_df, house_rent_day_df, how='outer', left_index=True, right_index=True)

    day_df = df_util.df_set_first_title(day_df, "今日数据")

    result_df = pd.merge(house_base_df, day_df, how='outer', left_index=True, right_index=True)

    house_sale_data_df = house_sale_data(st=st, et=et)
    sale_data_df = df_util.df_set_index(house_sale_data_df, "房屋ID")

    house_refund_rate_month_df = house_refund_rate_month(st=st, et=et)
    house_refund_rate_month_df = df_util.df_set_index(house_refund_rate_month_df, "房屋ID")

    total_df = pd.merge(sale_data_df, house_refund_rate_month_df, how='outer', left_index=True, right_index=True)
    total_df = df_util.df_set_first_title(total_df, "累计数据")
    test_dict['day_df'] = day_df
    test_dict['result_df'] = result_df
    test_dict['total_df'] = total_df

    excel_util.pd_to_excel(test_dict, "business_house1", merge_cells=True, engine='xlsxwriter')

    result_df = pd.merge(result_df, total_df, how='outer', left_index=True, right_index=True)

    tujia_order_df = channel_order(st=st, et=et, channel_id=TUJIA)
    tujia_tag_df = tujia_tag(dt=et)
    tujia_df = pd.merge(tujia_order_df, tujia_tag_df, how='outer')
    tujia_df = df_util.df_set_index(tujia_df, "房屋ID")
    tujia_df = df_util.df_set_first_title(tujia_df, "途家")
    result_df = pd.merge(result_df, tujia_df, how='outer', left_index=True, right_index=True)

    zhenguo_order_df = channel_order(st=st, et=et, channel_id=ZHENGUO)
    zhenguo_tag_df = zhenguo_tag(dt=et)
    zhenguo_df = pd.merge(zhenguo_order_df, zhenguo_tag_df, how='outer')
    zhenguo_df = df_util.df_set_index(zhenguo_df, "房屋ID")
    zhenguo_df = df_util.df_set_first_title(zhenguo_df, "榛果")
    result_df = pd.merge(result_df, zhenguo_df, how='outer', left_index=True, right_index=True)

    airbnb_order_df = channel_order(st=st, et=et, channel_id=AIRBNB)
    airbnb_tag_df = airbnb_tag(dt=et)
    airbnb_df = pd.merge(airbnb_order_df, airbnb_tag_df, how='outer')
    airbnb_df = df_util.df_set_index(airbnb_df, "房屋ID")
    airbnb_df = df_util.df_set_first_title(airbnb_df, "爱彼迎")
    result_df = pd.merge(result_df, airbnb_df, how='outer', left_index=True, right_index=True)

    result_df = result_df.reset_index()
    # result_df = df_util.df_set_index(result_df, '城市')

    return {'经营日报-房屋': result_df}, {'经营日报-房屋': DAY_REPORT_BUSINESS_COLOR}


def process(st=None, et=None):
    today = date_util.date_add(et, days=1) if et else date_util.curdate(0)
    yesterday = date_util.curdate()
    st = st if st else date_util.cur_month_first(days=1, dt=yesterday)
    et = et if et else yesterday

    log.info('开始处理 经营日报 st={st},et={et} '.format(st=st, et=et))
    df_dict = dict()
    color_dict = dict()
    city_df_dict, city_color_dict = business_city(st=st, et=et)
    df_dict.update(city_df_dict)
    color_dict.update(city_color_dict)

    # todo 服务中心维度去除
    #  service_df_dict, service_color_dict = business_service(st=st, et=et)
    #  df_dict.update(service_df_dict)
    #  color_dict.update(service_color_dict)

    work_df_dict, work_color_dict = business_work(st=st, et=et)
    df_dict.update(work_df_dict)
    color_dict.update(work_color_dict)

    # todo 销售维度有问题
    #  online_df_dict, online_color_dict = business_online(st=st, et=et)
    #  df_dict.update(online_df_dict)
    #  color_dict.update(online_color_dict)

    house_df_dict, house_color_dict = business_house(st=st, et=et)
    df_dict.update(house_df_dict)
    color_dict.update(house_color_dict)

    orders_df = orders(st=st, et=et)
    df_dict.update({"经营日报-订单": orders_df})

    text = """    Dear All:
                附件是经营日报整合！ 
                请查收！
                谢谢！
        如有问题！
        请联系: dt@iyoujia.com
        """
    mail_util.distribute_mail(df_dict=df_dict, file_name='经营日报整合', text=text, html_sheet_name='经营日报-城市',
                              title="【经营日报整合】", colors_dict=color_dict, receiver=receivers, na_rep='-',
                              engine='xlsxwriter',
                              city_mails=city_mails, city=True, city_key='城市', uuid='business', freeze_panes=(2, 2))


def run():
    # dt = dt if dt else date_util.curdate()
    try:
        # '2018-09-01','2018-09-30'
        process()
    except Exception as e:
        mail_util.error_mail("经营日报整合", e.__str__())
        log.exception(e)


if __name__ == '__main__':
    run()
